//
//  OMOrderRefundReasonInputTableCell.m
//  OMENGO_NEW
//
//  Created by 梁尚嘉 on 2017/5/16.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMInputTableCell.h"
@interface OMInputTableCell ()
@property (nonatomic, strong) UILabel *placeholdLabel;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UILabel *maxNumLabel;

@end
@implementation OMInputTableCell

- (void)configure
{
    [super configure];

    _placeholdLabel = [UILabel new];
    _placeholdLabel.font = SM_CFont(31);
    _placeholdLabel.textColor = SM_grayColor;
    _placeholdLabel.numberOfLines = 0;
    [self.contentView addSubview:_placeholdLabel];
    [_placeholdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@(SM_SIZE(24)));
        make.right.equalTo(@(SM_SIZE(-24)));
    }];

    _maxNumLabel = [UILabel new];
    _maxNumLabel.textColor = SM_grayColor;
    _maxNumLabel.font = SM_NFont(27);
    [self.contentView addSubview:_maxNumLabel];
    [_maxNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(SM_SIZE(-30)));
        make.bottom.equalTo(@(SM_SIZE(-30)));
    }];

    _textView = [UITextView new];
    _textView.font = SM_CFont(31);
    _textView.textColor = SM_blackColor;
    _textView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(SM_SIZE(20)));
        make.top.bottom.equalTo(@(SM_SIZE(5)));
        make.right.equalTo(@(SM_SIZE(-20)));
    }];

    @weakify(self);
    [[_textView rac_textSignal]subscribeNext:^(id x) {
        @strongify(self);
        if (self.textView.text.length>self.maxLength) {
            self.textView.text = [self.textView.text substringWithRange:NSMakeRange(0, self.maxLength)];
        }
        [self uploadMax];
    }];
}


- (void)setPlacehold:(NSString *)placehold

{
    _placehold = placehold ;
    _placeholdLabel.text = placehold;
}

- (void)setMaxLength:(NSUInteger)maxLength
{
    _maxLength = maxLength;
    [self uploadMax];
}

- (void)uploadMax
{

    self.placeholdLabel.hidden = self.textView.text.length;
    _maxNumLabel.text = [NSString stringWithFormat:@"%ld/%ld字",_textView.text.length,_maxLength];
    if (self.textDidChange) {
        self.textDidChange(self.textView.text);
    }
}
@end
